
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>TypeScript 1.6 · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="TypeScript 1.5.html" />
    
    
    <link rel="prev" href="TypeScript 1.7.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../handbook/tutorials/">
            
                <a href="../handbook/tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../handbook/tutorials/TypeScript in 5 minutes.html">
            
                <a href="../handbook/tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../handbook/tutorials/ASP.NET Core.html">
            
                <a href="../handbook/tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../handbook/tutorials/ASP.NET 4.html">
            
                <a href="../handbook/tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../handbook/tutorials/Gulp.html">
            
                <a href="../handbook/tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../handbook/tutorials/Knockout.html">
            
                <a href="../handbook/tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../handbook/tutorials/React & Webpack.html">
            
                <a href="../handbook/tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../handbook/tutorials/React.html">
            
                <a href="../handbook/tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../handbook/tutorials/Angular 2.html">
            
                <a href="../handbook/tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../handbook/tutorials/Migrating from JavaScript.html">
            
                <a href="../handbook/tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../handbook/">
            
                <a href="../handbook/">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../handbook/Basic Types.html">
            
                <a href="../handbook/Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../handbook/Variable Declarations.html">
            
                <a href="../handbook/Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../handbook/Interfaces.html">
            
                <a href="../handbook/Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../handbook/Classes.html">
            
                <a href="../handbook/Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../handbook/Functions.html">
            
                <a href="../handbook/Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../handbook/Generics.html">
            
                <a href="../handbook/Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../handbook/Enums.html">
            
                <a href="../handbook/Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../handbook/Type Inference.html">
            
                <a href="../handbook/Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../handbook/Type Compatibility.html">
            
                <a href="../handbook/Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../handbook/Advanced Types.html">
            
                <a href="../handbook/Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../handbook/Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../handbook/Symbols.html">
            
                <a href="../handbook/Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../handbook/Iterators and Generators.html">
            
                <a href="../handbook/Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="../handbook/Modules.html">
            
                <a href="../handbook/Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="../handbook/Namespaces.html">
            
                <a href="../handbook/Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="../handbook/Namespaces and Modules.html">
            
                <a href="../handbook/Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="../handbook/Module Resolution.html">
            
                <a href="../handbook/Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.18" data-path="../handbook/Declaration Merging.html">
            
                <a href="../handbook/Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="../handbook/Writing Definition Files.html">
            
                <a href="../handbook/Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.20" data-path="../handbook/JSX.html">
            
                <a href="../handbook/JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="../handbook/Decorators.html">
            
                <a href="../handbook/Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="../handbook/Mixins.html">
            
                <a href="../handbook/Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="../handbook/Triple-Slash Directives.html">
            
                <a href="../handbook/Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="../handbook/Type Checking JavaScript Files.html">
            
                <a href="../handbook/Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../handbook/declaration files/Introduction.html">
            
                <a href="../handbook/declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../handbook/declaration files/Library Structures.html">
            
                <a href="../handbook/declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../handbook/declaration files/Do's and Don'ts.html">
            
                <a href="../handbook/declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../handbook/declaration files/By Example.html">
            
                <a href="../handbook/declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../handbook/declaration files/Deep Dive.html">
            
                <a href="../handbook/declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../handbook/declaration files/Publishing.html">
            
                <a href="../handbook/declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../handbook/declaration files/Consumption.html">
            
                <a href="../handbook/declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../handbook/tsconfig.json.html">
            
                <a href="../handbook/tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../handbook/tsconfig.json.html">
            
                <a href="../handbook/tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../handbook/Project References.html">
            
                <a href="../handbook/Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../handbook/Typings for NPM Packages.html">
            
                <a href="../handbook/Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../handbook/Compiler Options.html">
            
                <a href="../handbook/Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../handbook/Configuring Watch.html">
            
                <a href="../handbook/Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../handbook/Compiler Options in MSBuild.html">
            
                <a href="../handbook/Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../handbook/Integrating with Build Tools.html">
            
                <a href="../handbook/Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../handbook/Nightly Builds.html">
            
                <a href="../handbook/Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="TypeScript 3.1.html">
            
                <a href="TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="TypeScript 3.0.html">
            
                <a href="TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="TypeScript 2.9.html">
            
                <a href="TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="TypeScript 2.8.html">
            
                <a href="TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="TypeScript 2.7.html">
            
                <a href="TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="TypeScript 2.6.html">
            
                <a href="TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="TypeScript 2.5.html">
            
                <a href="TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="TypeScript 2.4.html">
            
                <a href="TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="TypeScript 2.3.html">
            
                <a href="TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="TypeScript 2.2.html">
            
                <a href="TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="TypeScript 2.1.html">
            
                <a href="TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="TypeScript 2.0.html">
            
                <a href="TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="TypeScript 1.8.html">
            
                <a href="TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="TypeScript 1.7.html">
            
                <a href="TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.15" data-path="TypeScript 1.6.html">
            
                <a href="TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="TypeScript 1.5.html">
            
                <a href="TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="TypeScript 1.4.html">
            
                <a href="TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="TypeScript 1.3.html">
            
                <a href="TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="TypeScript 1.1.html">
            
                <a href="TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >TypeScript 1.6</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="typescript-16">TypeScript 1.6</h1>
<h2 id="jsx-&#x652F;&#x6301;">JSX &#x652F;&#x6301;</h2>
<p>JSX &#x662F;&#x4E00;&#x79CD;&#x53EF;&#x5D4C;&#x5165;&#x7684;&#x7C7B;&#x4F3C; XML &#x7684;&#x8BED;&#x6CD5;. &#x5B83;&#x5C06;&#x6700;&#x7EC8;&#x88AB;&#x8F6C;&#x6362;&#x4E3A;&#x5408;&#x6CD5;&#x7684; JavaScript, &#x4F46;&#x8F6C;&#x6362;&#x7684;&#x8BED;&#x4E49;&#x548C;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x6709;&#x5173;. JSX &#x968F;&#x7740; React &#x6D41;&#x884C;&#x8D77;&#x6765;, &#x4E5F;&#x51FA;&#x73B0;&#x5728;&#x5176;&#x4ED6;&#x5E94;&#x7528;&#x4E2D;. TypeScript 1.6 &#x652F;&#x6301; JavaScript &#x6587;&#x4EF6;&#x4E2D; JSX &#x7684;&#x5D4C;&#x5165;, &#x7C7B;&#x578B;&#x68C0;&#x67E5;, &#x4EE5;&#x53CA;&#x76F4;&#x63A5;&#x7F16;&#x8BD1;&#x4E3A; JavaScript &#x7684;&#x9009;&#x9879;.</p>
<h3 id="&#x65B0;&#x7684;-tsx-&#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;&#x548C;-as-&#x8FD0;&#x7B97;&#x7B26;">&#x65B0;&#x7684; <code>.tsx</code> &#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;&#x548C; <code>as</code> &#x8FD0;&#x7B97;&#x7B26;</h3>
<p>TypeScript 1.6 &#x5F15;&#x5165;&#x4E86;&#x65B0;&#x7684; <code>.tsx</code> &#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;. &#x8FD9;&#x4E00;&#x6269;&#x5C55;&#x540D;&#x4E00;&#x65B9;&#x9762;&#x5141;&#x8BB8; TypeScript &#x6587;&#x4EF6;&#x4E2D;&#x7684; JSX &#x8BED;&#x6CD5;, &#x4E00;&#x65B9;&#x9762;&#x5C06; <code>as</code> &#x8FD0;&#x7B97;&#x7B26;&#x4F5C;&#x4E3A;&#x9ED8;&#x8BA4;&#x7684;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x65B9;&#x5F0F; (&#x907F;&#x514D; JSX &#x8868;&#x8FBE;&#x5F0F;&#x548C; TypeScript &#x524D;&#x7F6E;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x8FD0;&#x7B97;&#x7B26;&#x4E4B;&#x95F4;&#x7684;&#x6B67;&#x4E49;). &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> x = &lt;<span class="hljs-built_in">any</span>&gt; foo;
<span class="hljs-comment">// &#x4E0E;&#x5982;&#x4E0B;&#x7B49;&#x4EF7;:</span>
<span class="hljs-keyword">var</span> x = foo as <span class="hljs-built_in">any</span>;
</code></pre>
<h3 id="&#x4F7F;&#x7528;-react">&#x4F7F;&#x7528; React</h3>
<p>&#x4F7F;&#x7528; React &#x53CA; JSX &#x652F;&#x6301;, &#x4F60;&#x9700;&#x8981;&#x4F7F;&#x7528; <a href="https://github.com/borisyankov/DefinitelyTyped/tree/master/react" target="_blank">React &#x7C7B;&#x578B;&#x58F0;&#x660E;</a>. &#x8FD9;&#x4E9B;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x4E86; <code>JSX</code> &#x547D;&#x540D;&#x7A7A;&#x95F4;, &#x4EE5;&#x4FBF; TypeScript &#x80FD;&#x6B63;&#x786E;&#x5730;&#x68C0;&#x67E5; React &#x7684; JSX &#x8868;&#x8FBE;&#x5F0F;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts">/// &lt;reference path=&quot;react.d.ts&quot; /&gt;

interface Props {
  name: string;
}

class MyComponent extends React.Component&lt;Props, {}&gt; {
  render() {
    return &lt;span&gt;{this.props.foo}&lt;/span&gt;
  }
}

&lt;MyComponent name=&quot;bar&quot; /&gt;; // &#x6CA1;&#x95EE;&#x9898;
&lt;MyComponent name={0} /&gt;; // &#x9519;&#x8BEF;, `name` &#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;
</code></pre>
<h3 id="&#x4F7F;&#x7528;&#x5176;&#x4ED6;-jsx-&#x6846;&#x67B6;">&#x4F7F;&#x7528;&#x5176;&#x4ED6; JSX &#x6846;&#x67B6;</h3>
<p>JSX &#x5143;&#x7D20;&#x7684;&#x540D;&#x79F0;&#x548C;&#x5C5E;&#x6027;&#x662F;&#x6839;&#x636E; <code>JSX</code> &#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6765;&#x68C0;&#x9A8C;&#x7684;. &#x8BF7;&#x67E5;&#x770B; <a href="https://github.com/Microsoft/TypeScript/wiki/JSX" target="_blank">JSX</a> &#x9875;&#x9762;&#x4E86;&#x89E3;&#x5982;&#x4F55;&#x4E3A;&#x81EA;&#x5DF1;&#x7684;&#x6846;&#x67B6;&#x5B9A;&#x4E49; <code>JSX</code> &#x547D;&#x540D;&#x7A7A;&#x95F4;.</p>
<h3 id="&#x7F16;&#x8BD1;&#x8F93;&#x51FA;">&#x7F16;&#x8BD1;&#x8F93;&#x51FA;</h3>
<p>TypeScript &#x652F;&#x6301;&#x4E24;&#x79CD; <code>JSX</code> &#x6A21;&#x5F0F;: <code>preserve</code> (&#x4FDD;&#x7559;) &#x548C; <code>react</code>.</p>
<ul>
<li><code>preserve</code> &#x6A21;&#x5F0F;&#x5C06;&#x4F1A;&#x5728;&#x8F93;&#x51FA;&#x4E2D;&#x4FDD;&#x7559; JSX &#x8868;&#x8FBE;&#x5F0F;, &#x4F7F;&#x4E4B;&#x540E;&#x7684;&#x8F6C;&#x6362;&#x6B65;&#x9AA4;&#x53EF;&#x4EE5;&#x5904;&#x7406;. <em>&#x5E76;&#x4E14;&#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;&#x4E3A; <code>.jsx</code>.</em></li>
<li><code>react</code> &#x6A21;&#x5F0F;&#x5C06;&#x4F1A;&#x751F;&#x6210; <code>React.createElement</code>, &#x4E0D;&#x518D;&#x9700;&#x8981;&#x518D;&#x901A;&#x8FC7; JSX &#x8F6C;&#x6362;&#x5373;&#x53EF;&#x8FD0;&#x884C;, &#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;&#x4E3A; <code>.js</code>.</li>
</ul>
<p>&#x67E5;&#x770B; <a href="https://github.com/Microsoft/TypeScript/wiki/JSX" target="_blank">JSX</a> &#x9875;&#x9762;&#x4E86;&#x89E3;&#x66F4;&#x591A; JSX &#x5728; TypeScript &#x4E2D;&#x7684;&#x4F7F;&#x7528;.</p>
<h2 id="&#x4EA4;&#x53C9;&#x7C7B;&#x578B;-intersection-types">&#x4EA4;&#x53C9;&#x7C7B;&#x578B; (intersection types)</h2>
<p>TypeScript 1.6 &#x5F15;&#x5165;&#x4E86;&#x4EA4;&#x53C9;&#x7C7B;&#x578B;&#x4F5C;&#x4E3A;&#x8054;&#x5408;&#x7C7B;&#x578B; (union types) &#x903B;&#x8F91;&#x4E0A;&#x7684;&#x8865;&#x5145;. &#x8054;&#x5408;&#x7C7B;&#x578B; <code>A | B</code> &#x8868;&#x793A;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x4E3A; <code>A</code> &#x6216; <code>B</code> &#x7684;&#x5B9E;&#x4F53;, &#x800C;&#x4EA4;&#x53C9;&#x7C7B;&#x578B; <code>A &amp; B</code> &#x8868;&#x793A;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x540C;&#x65F6;&#x4E3A; <code>A</code> &#x6216; <code>B</code> &#x7684;&#x5B9E;&#x4F53;.</p>
<h3 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h3>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">extend</span>&lt;<span class="hljs-title">T</span>, <span class="hljs-title">U</span>&gt;(<span class="hljs-params">first: T, second: U</span>): <span class="hljs-title">T</span> &amp; <span class="hljs-title">U</span> </span>{
    <span class="hljs-keyword">let</span> result = &lt;T &amp; U&gt; {};
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> id <span class="hljs-keyword">in</span> first) {
        result[id] = first[id];
    }
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> id <span class="hljs-keyword">in</span> second) {
        <span class="hljs-keyword">if</span> (!result.hasOwnProperty(id)) {
            result[id] = second[id];
        }
    }
    <span class="hljs-keyword">return</span> result;
}

<span class="hljs-keyword">var</span> x = extend({ a: <span class="hljs-string">&quot;hello&quot;</span> }, { b: <span class="hljs-number">42</span> });
<span class="hljs-keyword">var</span> s = x.a;
<span class="hljs-keyword">var</span> n = x.b;
</code></pre>
<pre><code class="lang-ts"><span class="hljs-keyword">type</span> LinkedList&lt;T&gt; = T &amp; { next: LinkedList&lt;T&gt; };

<span class="hljs-keyword">interface</span> Person {
    name: <span class="hljs-built_in">string</span>;
}

<span class="hljs-keyword">var</span> people: LinkedList&lt;Person&gt;;
<span class="hljs-keyword">var</span> s = people.name;
<span class="hljs-keyword">var</span> s = people.next.name;
<span class="hljs-keyword">var</span> s = people.next.next.name;
<span class="hljs-keyword">var</span> s = people.next.next.next.name;
<span class="hljs-keyword">interface</span> A { a: <span class="hljs-built_in">string</span> }
<span class="hljs-keyword">interface</span> B { b: <span class="hljs-built_in">string</span> }
<span class="hljs-keyword">interface</span> C { c: <span class="hljs-built_in">string</span> }

<span class="hljs-keyword">var</span> abc: A &amp; B &amp; C;
abc.a = <span class="hljs-string">&quot;hello&quot;</span>;
abc.b = <span class="hljs-string">&quot;hello&quot;</span>;
abc.c = <span class="hljs-string">&quot;hello&quot;</span>;
</code></pre>
<p>&#x67E5;&#x770B; <a href="https://github.com/Microsoft/TypeScript/issues/1256" target="_blank">issue #1256</a> &#x4E86;&#x89E3;&#x66F4;&#x591A;.</p>
<h2 id="&#x672C;&#x5730;&#x7C7B;&#x578B;&#x58F0;&#x660E;">&#x672C;&#x5730;&#x7C7B;&#x578B;&#x58F0;&#x660E;</h2>
<p>&#x672C;&#x5730;&#x7684;&#x7C7B;, &#x63A5;&#x53E3;, &#x679A;&#x4E3E;&#x548C;&#x7C7B;&#x578B;&#x522B;&#x540D;&#x73B0;&#x5728;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E2D;&#x51FA;&#x73B0;. &#x672C;&#x5730;&#x7C7B;&#x578B;&#x4E3A;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;, &#x4E0E; <code>let</code> &#x548C; <code>const</code> &#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x7C7B;&#x4F3C;. &#x6BD4;&#x5982;&#x8BF4;:</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
        <span class="hljs-keyword">interface</span> T { x: <span class="hljs-built_in">number</span> }
        <span class="hljs-keyword">let</span> v: T;
        v.x = <span class="hljs-number">5</span>;
    }
    <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">interface</span> T { x: <span class="hljs-built_in">string</span> }
        <span class="hljs-keyword">let</span> v: T;
        v.x = <span class="hljs-string">&quot;hello&quot;</span>;
    }
}
</code></pre>
<p>&#x63A8;&#x5BFC;&#x51FA;&#x7684;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x53EF;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;. &#x8C03;&#x7528;&#x51FD;&#x6570;&#x7684;&#x5730;&#x65B9;&#x65E0;&#x6CD5;&#x5F15;&#x7528;&#x5230;&#x8FD9;&#x6837;&#x7684;&#x672C;&#x5730;&#x7C7B;&#x578B;, &#x4F46;&#x662F;&#x5B83;&#x5F53;&#x7136;&#x80FD;&#x4ECE;&#x7C7B;&#x578B;&#x7ED3;&#x6784;&#x4E0A;&#x5339;&#x914D;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Point {
    x: <span class="hljs-built_in">number</span>;
    y: <span class="hljs-built_in">number</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getPointFactory</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>) </span>{
    <span class="hljs-keyword">class</span> P {
        x = x;
        y = y;
    }
    <span class="hljs-keyword">return</span> P;
}

<span class="hljs-keyword">var</span> PointZero = getPointFactory(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>);
<span class="hljs-keyword">var</span> PointOne = getPointFactory(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>);
<span class="hljs-keyword">var</span> p1 = <span class="hljs-keyword">new</span> PointZero();
<span class="hljs-keyword">var</span> p2 = <span class="hljs-keyword">new</span> PointZero();
<span class="hljs-keyword">var</span> p3 = <span class="hljs-keyword">new</span> PointOne();
</code></pre>
<p>&#x672C;&#x5730;&#x7684;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x53C2;&#x6570;, &#x672C;&#x5730;&#x7684;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x672C;&#x8EAB;&#x5373;&#x53EF;&#x80FD;&#x662F;&#x6CDB;&#x578B;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f3</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>&lt;<span class="hljs-title">X</span>, <span class="hljs-title">Y</span>&gt;(<span class="hljs-params">x: X, y: Y</span>) </span>{
        <span class="hljs-keyword">class</span> C {
            <span class="hljs-keyword">public</span> x = x;
            <span class="hljs-keyword">public</span> y = y;
        }
        <span class="hljs-keyword">return</span> C;
    }
    <span class="hljs-keyword">let</span> C = f(<span class="hljs-number">10</span>, <span class="hljs-string">&quot;hello&quot;</span>);
    <span class="hljs-keyword">let</span> v = <span class="hljs-keyword">new</span> C();
    <span class="hljs-keyword">let</span> x = v.x;  <span class="hljs-comment">// number</span>
    <span class="hljs-keyword">let</span> y = v.y;  <span class="hljs-comment">// string</span>
}
</code></pre>
<h2 id="&#x7C7B;&#x8868;&#x8FBE;&#x5F0F;">&#x7C7B;&#x8868;&#x8FBE;&#x5F0F;</h2>
<p>TypeScript 1.6 &#x589E;&#x52A0;&#x4E86;&#x5BF9; ES6 &#x7C7B;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x652F;&#x6301;. &#x5728;&#x4E00;&#x4E2A;&#x7C7B;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;, &#x7C7B;&#x7684;&#x540D;&#x79F0;&#x662F;&#x53EF;&#x9009;&#x7684;, &#x5982;&#x679C;&#x6307;&#x660E;, &#x4F5C;&#x7528;&#x57DF;&#x4EC5;&#x9650;&#x4E8E;&#x7C7B;&#x8868;&#x8FBE;&#x5F0F;&#x672C;&#x8EAB;. &#x8FD9;&#x548C;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x9009;&#x7684;&#x540D;&#x79F0;&#x7C7B;&#x4F3C;. &#x5728;&#x7C7B;&#x8868;&#x8FBE;&#x5F0F;&#x5916;&#x65E0;&#x6CD5;&#x5F15;&#x7528;&#x5176;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;, &#x4F46;&#x662F;&#x81EA;&#x7136;&#x4E5F;&#x80FD;&#x591F;&#x4ECE;&#x7C7B;&#x578B;&#x7ED3;&#x6784;&#x4E0A;&#x5339;&#x914D;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> Point = <span class="hljs-keyword">class</span> {
    <span class="hljs-keyword">constructor</span>(public x: number, public y: number) { }
    <span class="hljs-keyword">public</span> length() {
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.sqrt(<span class="hljs-keyword">this</span>.x * <span class="hljs-keyword">this</span>.x + <span class="hljs-keyword">this</span>.y * <span class="hljs-keyword">this</span>.y);
    }
};
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Point(<span class="hljs-number">3</span>, <span class="hljs-number">4</span>);  <span class="hljs-comment">// p has anonymous class type</span>
<span class="hljs-built_in">console</span>.log(p.length());
</code></pre>
<h2 id="&#x7EE7;&#x627F;&#x8868;&#x8FBE;&#x5F0F;">&#x7EE7;&#x627F;&#x8868;&#x8FBE;&#x5F0F;</h2>
<p>TypeScript 1.6 &#x589E;&#x52A0;&#x4E86;&#x5BF9;&#x7C7B;&#x7EE7;&#x627F;&#x4EFB;&#x610F;&#x503C;&#x4E3A;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x652F;&#x6301;. &#x8FD9;&#x6837;&#x4E00;&#x6765;&#x5185;&#x5EFA;&#x7684;&#x7C7B;&#x578B;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x7C7B;&#x7684;&#x58F0;&#x660E;&#x4E2D;&#x88AB;&#x7EE7;&#x627F;.</p>
<p><code>extends</code> &#x8BED;&#x53E5;&#x8FC7;&#x53BB;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x5F15;&#x7528;, &#x73B0;&#x5728;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x7684;&#x8868;&#x8FBE;&#x5F0F;. &#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x7C7B;&#x578B;&#x5FC5;&#x987B;&#x4E3A;&#x6709;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;, &#x5E76;&#x4E14;&#x9700;&#x8981;&#x548C; <code>extends</code> &#x8BED;&#x53E5;&#x4E2D;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x6570;&#x91CF;&#x4E00;&#x81F4;. &#x5339;&#x914D;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x662F;&#x7C7B;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x7EE7;&#x627F;&#x7684;&#x57FA;&#x7C7B;&#x578B;. &#x5982;&#x6B64;&#x4E00;&#x6765;, &#x8FD9;&#x4F7F;&#x5F97;&#x666E;&#x901A;&#x7684;&#x7C7B;&#x548C;&#x4E0E;&#x7C7B;&#x76F8;&#x4F3C;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x5728; <code>extends</code> &#x8BED;&#x53E5;&#x4E2D;&#x4F7F;&#x7528;.</p>
<p>&#x4E00;&#x4E9B;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-ts"><span class="hljs-comment">// &#x7EE7;&#x627F;&#x5185;&#x5EFA;&#x7C7B;</span>

<span class="hljs-keyword">class</span> MyArray extends <span class="hljs-built_in">Array</span>&lt;<span class="hljs-built_in">number</span>&gt; { }
<span class="hljs-keyword">class</span> MyError extends <span class="hljs-built_in">Error</span> { }

<span class="hljs-comment">// &#x7EE7;&#x627F;&#x8868;&#x8FBE;&#x5F0F;&#x7C7B;</span>

<span class="hljs-keyword">class</span> ThingA {
    getGreeting() { <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Hello from A&quot;</span>; }
}

<span class="hljs-keyword">class</span> ThingB {
    getGreeting() { <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Hello from B&quot;</span>; }
}

<span class="hljs-keyword">interface</span> Greeter {
    getGreeting(): <span class="hljs-built_in">string</span>;
}

<span class="hljs-keyword">interface</span> GreeterConstructor {
    <span class="hljs-keyword">new</span> (): Greeter;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getGreeterBase</span>(<span class="hljs-params"></span>): <span class="hljs-title">GreeterConstructor</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.random() &gt;= <span class="hljs-number">0.5</span> ? ThingA : ThingB;
}

<span class="hljs-keyword">class</span> Test extends getGreeterBase() {
    sayHello() {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.getGreeting());
    }
}
</code></pre>
<h2 id="abstract-&#x62BD;&#x8C61;&#x7684;-&#x7C7B;&#x548C;&#x65B9;&#x6CD5;"><code>abstract</code> (&#x62BD;&#x8C61;&#x7684;) &#x7C7B;&#x548C;&#x65B9;&#x6CD5;</h2>
<p>TypeScript 1.6 &#x4E3A;&#x7C7B;&#x548C;&#x5B83;&#x4EEC;&#x7684;&#x65B9;&#x6CD5;&#x589E;&#x52A0;&#x4E86; <code>abstract</code> &#x5173;&#x952E;&#x5B57;. &#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x5141;&#x8BB8;&#x6CA1;&#x6709;&#x88AB;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;, &#x5E76;&#x4E14;&#x4E0D;&#x80FD;&#x88AB;&#x6784;&#x9020;.</p>
<h3 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h3>
<pre><code class="lang-ts"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> Base {
    <span class="hljs-keyword">abstract</span> getThing(): <span class="hljs-built_in">string</span>;
    getOtherThing() { <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;hello&apos;</span>; }
}

<span class="hljs-keyword">let</span> x = <span class="hljs-keyword">new</span> Base(); <span class="hljs-comment">// &#x9519;&#x8BEF;, &apos;Base&apos; &#x662F;&#x62BD;&#x8C61;&#x7684;</span>

<span class="hljs-comment">// &#x9519;&#x8BEF;, &#x5FC5;&#x987B;&#x4E5F;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;, &#x6216;&#x8005;&#x5B9E;&#x73B0; &apos;getThing&apos; &#x65B9;&#x6CD5;</span>
<span class="hljs-keyword">class</span> Derived1 extends Base { }

<span class="hljs-keyword">class</span> Derived2 extends Base {
    getThing() { <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;hello&apos;</span>; }
    foo() {
        <span class="hljs-keyword">super</span>.getThing();<span class="hljs-comment">// &#x9519;&#x8BEF;: &#x4E0D;&#x80FD;&#x8C03;&#x7528; &apos;super&apos; &#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;</span>
    }
}

<span class="hljs-keyword">var</span> x = <span class="hljs-keyword">new</span> Derived2(); <span class="hljs-comment">// &#x6B63;&#x786E;</span>
<span class="hljs-keyword">var</span> y: Base = <span class="hljs-keyword">new</span> Derived2(); <span class="hljs-comment">// &#x540C;&#x6837;&#x6B63;&#x786E;</span>
y.getThing(); <span class="hljs-comment">// &#x6B63;&#x786E;</span>
y.getOtherThing(); <span class="hljs-comment">// &#x6B63;&#x786E;</span>
</code></pre>
<h2 id="&#x6CDB;&#x578B;&#x522B;&#x540D;">&#x6CDB;&#x578B;&#x522B;&#x540D;</h2>
<p>TypeScript 1.6 &#x4E2D;, &#x7C7B;&#x578B;&#x522B;&#x540D;&#x652F;&#x6301;&#x6CDB;&#x578B;. &#x6BD4;&#x5982;:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">type</span> Lazy&lt;T&gt; = T | (() =&gt; T);

<span class="hljs-keyword">var</span> s: Lazy&lt;<span class="hljs-built_in">string</span>&gt;;
s = <span class="hljs-string">&quot;eager&quot;</span>;
s = () =&gt; <span class="hljs-string">&quot;lazy&quot;</span>;

<span class="hljs-keyword">interface</span> Tuple&lt;A, B&gt; {
    a: A;
    b: B;
}

<span class="hljs-keyword">type</span> Pair&lt;T&gt; = Tuple&lt;T, T&gt;;
</code></pre>
<h2 id="&#x66F4;&#x4E25;&#x683C;&#x7684;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x8D4B;&#x503C;&#x68C0;&#x67E5;">&#x66F4;&#x4E25;&#x683C;&#x7684;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x8D4B;&#x503C;&#x68C0;&#x67E5;</h2>
<p>&#x4E3A;&#x4E86;&#x80FD;&#x53D1;&#x73B0;&#x591A;&#x4F59;&#x6216;&#x8005;&#x9519;&#x8BEF;&#x62FC;&#x5199;&#x7684;&#x5C5E;&#x6027;, TypeScript 1.6 &#x4F7F;&#x7528;&#x4E86;&#x66F4;&#x4E25;&#x683C;&#x7684;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x68C0;&#x67E5;. &#x786E;&#x5207;&#x5730;&#x8BF4;, &#x5728;&#x5C06;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;, &#x6216;&#x8005;&#x4F20;&#x9012;&#x7ED9;&#x7C7B;&#x578B;&#x975E;&#x7A7A;&#x7684;&#x53C2;&#x6570;&#x65F6;, &#x5982;&#x679C;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x5C5E;&#x6027;&#x5728;&#x76EE;&#x6807;&#x7C7B;&#x578B;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;, &#x5219;&#x4F1A;&#x89C6;&#x4E3A;&#x9519;&#x8BEF;.</p>
<h3 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h3>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> x: { foo: <span class="hljs-built_in">number</span> };
x = { foo: <span class="hljs-number">1</span>, baz: <span class="hljs-number">2</span> };  <span class="hljs-comment">// &#x9519;&#x8BEF;, &#x591A;&#x4F59;&#x7684;&#x5C5E;&#x6027; `baz`</span>

<span class="hljs-keyword">var</span> y: { foo: <span class="hljs-built_in">number</span>, bar?: <span class="hljs-built_in">number</span> };
y = { foo: <span class="hljs-number">1</span>, baz: <span class="hljs-number">2</span> };  <span class="hljs-comment">// &#x9519;&#x8BEF;, &#x591A;&#x4F59;&#x6216;&#x8005;&#x62FC;&#x9519;&#x7684;&#x5C5E;&#x6027; `baz`</span>
</code></pre>
<p>&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x7B7E;&#x540D;&#x6765;&#x663E;&#x793A;&#x6307;&#x660E;&#x672A;&#x51FA;&#x73B0;&#x5728;&#x7C7B;&#x578B;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x662F;&#x88AB;&#x5141;&#x8BB8;&#x7684;.</p>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> x: { foo: <span class="hljs-built_in">number</span>, [x: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> };
x = { foo: <span class="hljs-number">1</span>, baz: <span class="hljs-number">2</span> };  <span class="hljs-comment">// &#x73B0;&#x5728; `baz` &#x5339;&#x914D;&#x4E86;&#x7D22;&#x5F15;&#x7B7E;&#x540D;</span>
</code></pre>
<h2 id="es6-&#x751F;&#x6210;&#x5668;-generators">ES6 &#x751F;&#x6210;&#x5668; (generators)</h2>
<p>TypeScript 1.6 &#x6DFB;&#x52A0;&#x4E86;&#x5BF9;&#x4E8E; ES6 &#x8F93;&#x51FA;&#x7684;&#x751F;&#x6210;&#x5668;&#x652F;&#x6301;.</p>
<p>&#x4E00;&#x4E2A;&#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x6807;&#x6CE8;, &#x5C31;&#x50CF;&#x666E;&#x901A;&#x7684;&#x51FD;&#x6570;. &#x6807;&#x6CE8;&#x8868;&#x793A;&#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x7684;&#x751F;&#x6210;&#x5668;&#x7684;&#x7C7B;&#x578B;. &#x8FD9;&#x91CC;&#x6709;&#x4E2A;&#x4F8B;&#x5B50;:</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> *<span class="hljs-title">g</span>(<span class="hljs-params"></span>): <span class="hljs-title">Iterable</span>&lt;<span class="hljs-title">string</span>&gt; </span>{
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">100</span>; i++) {
        <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;&quot;</span>; <span class="hljs-comment">// string &#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x7ED9; string</span>
    }
    <span class="hljs-keyword">yield</span> * otherStringGenerator(); <span class="hljs-comment">// otherStringGenerator &#x5FC5;&#x987B;&#x53EF;&#x904D;&#x5386;, &#x5E76;&#x4E14;&#x5143;&#x7D20;&#x7C7B;&#x578B;&#x9700;&#x8981;&#x53EF;&#x8D4B;&#x503C;&#x7ED9; string</span>
}
</code></pre>
<p>&#x6CA1;&#x6709;&#x6807;&#x6CE8;&#x7C7B;&#x578B;&#x7684;&#x751F;&#x6210;&#x5668;&#x51FD;&#x6570;&#x4F1A;&#x6709;&#x81EA;&#x52A8;&#x63A8;&#x6F14;&#x7684;&#x7C7B;&#x578B;. &#x5728;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;, &#x7C7B;&#x578B;&#x4F1A;&#x7531; yield &#x8BED;&#x53E5;&#x63A8;&#x6F14;&#x51FA;&#x6765;:</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> *<span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">100</span>; i++) {
        <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;&quot;</span>; <span class="hljs-comment">// &#x63A8;&#x5BFC;&#x51FA; string</span>
    }
    <span class="hljs-keyword">yield</span> * otherStringGenerator(); <span class="hljs-comment">// &#x63A8;&#x5BFC;&#x51FA; otherStringGenerator &#x7684;&#x5143;&#x7D20;&#x7C7B;&#x578B;</span>
}
</code></pre>
<h2 id="&#x5BF9;-async-&#x5F02;&#x6B65;-&#x51FD;&#x6570;&#x7684;&#x8BD5;&#x9A8C;&#x6027;&#x652F;&#x6301;">&#x5BF9; <code>async</code> (&#x5F02;&#x6B65;) &#x51FD;&#x6570;&#x7684;&#x8BD5;&#x9A8C;&#x6027;&#x652F;&#x6301;</h2>
<p>TypeScript 1.6 &#x589E;&#x52A0;&#x4E86;&#x7F16;&#x8BD1;&#x5230; ES6 &#x65F6;&#x5BF9; <code>async</code> &#x51FD;&#x6570;&#x8BD5;&#x9A8C;&#x6027;&#x7684;&#x652F;&#x6301;. &#x5F02;&#x6B65;&#x51FD;&#x6570;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x5F02;&#x6B65;&#x7684;&#x64CD;&#x4F5C;, &#x5728;&#x7B49;&#x5F85;&#x7684;&#x540C;&#x65F6;&#x4E0D;&#x4F1A;&#x963B;&#x585E;&#x7A0B;&#x5E8F;&#x7684;&#x6B63;&#x5E38;&#x8FD0;&#x884C;. &#x8FD9;&#x662F;&#x901A;&#x8FC7;&#x4E0E; ES6 &#x517C;&#x5BB9;&#x7684; <code>Promise</code> &#x5B9E;&#x73B0;&#x5B8C;&#x6210;&#x7684;, &#x5E76;&#x4E14;&#x4F1A;&#x5C06;&#x51FD;&#x6570;&#x4F53;&#x8F6C;&#x6362;&#x4E3A;&#x652F;&#x6301;&#x5728;&#x7B49;&#x5F85;&#x7684;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#x5B8C;&#x6210;&#x65F6;&#x7EE7;&#x7EED;&#x7684;&#x5F62;&#x5F0F;.</p>
<p>&#x7531; <code>async</code> &#x6807;&#x8BB0;&#x7684;&#x51FD;&#x6570;&#x6216;&#x65B9;&#x6CD5;&#x88AB;&#x79F0;&#x4F5C;<em>&#x5F02;&#x6B65;&#x51FD;&#x6570;</em>. &#x8FD9;&#x4E2A;&#x6807;&#x8BB0;&#x544A;&#x8BC9;&#x4E86;&#x7F16;&#x8BD1;&#x5668;&#x8BE5;&#x51FD;&#x6570;&#x4F53;&#x9700;&#x8981;&#x88AB;&#x8F6C;&#x6362;, &#x5173;&#x952E;&#x5B57; <em>await</em> &#x5219;&#x5E94;&#x8BE5;&#x88AB;&#x5F53;&#x505A;&#x4E00;&#x4E2A;&#x4E00;&#x5143;&#x8FD0;&#x7B97;&#x7B26;, &#x800C;&#x4E0D;&#x662F;&#x6807;&#x793A;&#x7B26;. &#x4E00;&#x4E2A;<em>&#x5F02;&#x6B65;&#x51FD;&#x6570;</em>&#x5FC5;&#x987B;&#x8FD4;&#x56DE;&#x7C7B;&#x578B;&#x4E0E; <code>Promise</code> &#x517C;&#x5BB9;&#x7684;&#x503C;. &#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x7684;&#x63A8;&#x65AD;&#x53EA;&#x80FD;&#x5728;&#x6709;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x7684;, &#x4E0E; ES6 &#x517C;&#x5BB9;&#x7684; <code>Promise</code> &#x7C7B;&#x578B;&#x65F6;&#x4F7F;&#x7528;.</p>
<h3 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h3>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> p: Promise&lt;<span class="hljs-built_in">number</span>&gt; = <span class="hljs-comment">/* ... */</span>;
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>): <span class="hljs-title">Promise</span>&lt;<span class="hljs-title">number</span>&gt; </span>{
  <span class="hljs-keyword">var</span> i = await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;&#x76F4;&#x5230; &apos;p&apos; &#x5F97;&#x5230;&#x7ED3;&#x679C;. &apos;i&apos; &#x7684;&#x7C7B;&#x578B;&#x4E3A; &quot;number&quot;</span>
  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + i;
}

<span class="hljs-keyword">var</span> a = async (): Promise&lt;<span class="hljs-built_in">number</span>&gt; =&gt; <span class="hljs-number">1</span> + await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;.</span>
<span class="hljs-keyword">var</span> a = async () =&gt; <span class="hljs-number">1</span> + await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;. &#x4F7F;&#x7528; --target ES6 &#x9009;&#x9879;&#x7F16;&#x8BD1;&#x65F6;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x88AB;&#x63A8;&#x65AD;&#x4E3A; &quot;Promise&lt;number&gt;&quot;</span>
<span class="hljs-keyword">var</span> fe = async <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>): <span class="hljs-title">Promise</span>&lt;<span class="hljs-title">number</span>&gt; </span>{
  <span class="hljs-keyword">var</span> i = await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;&#x77E5;&#x9053; &apos;p&apos; &#x5F97;&#x5230;&#x7ED3;&#x679C;. &apos;i&apos; &#x7684;&#x7C7B;&#x578B;&#x4E3A; &quot;number&quot;</span>
  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + i;
}

<span class="hljs-keyword">class</span> C {
  async m(): Promise&lt;<span class="hljs-built_in">number</span>&gt; {
    <span class="hljs-keyword">var</span> i = await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;&#x77E5;&#x9053; &apos;p&apos; &#x5F97;&#x5230;&#x7ED3;&#x679C;. &apos;i&apos; &#x7684;&#x7C7B;&#x578B;&#x4E3A; &quot;number&quot;</span>
    <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + i;
  }

  async <span class="hljs-keyword">get</span> p(): Promise&lt;<span class="hljs-built_in">number</span>&gt; {
    <span class="hljs-keyword">var</span> i = await p; <span class="hljs-comment">// &#x6682;&#x505C;&#x6267;&#x884C;&#x77E5;&#x9053; &apos;p&apos; &#x5F97;&#x5230;&#x7ED3;&#x679C;. &apos;i&apos; &#x7684;&#x7C7B;&#x578B;&#x4E3A; &quot;number&quot;</span>
    <span class="hljs-keyword">return</span> <span class="hljs-number">1</span> + i;
  }
}
</code></pre>
<h2 id="&#x6BCF;&#x5929;&#x53D1;&#x5E03;&#x65B0;&#x7248;&#x672C;">&#x6BCF;&#x5929;&#x53D1;&#x5E03;&#x65B0;&#x7248;&#x672C;</h2>
<p>&#x7531;&#x4E8E;&#x5E76;&#x4E0D;&#x7B97;&#x4E25;&#x683C;&#x610F;&#x4E49;&#x4E0A;&#x7684;&#x8BED;&#x8A00;&#x53D8;&#x5316;<sup>[2]</sup>, &#x6BCF;&#x5929;&#x7684;&#x65B0;&#x7248;&#x672C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x5B89;&#x88C5;&#x83B7;&#x5F97;:</p>
<pre><code class="lang-sh">npm install -g typescript@next
</code></pre>
<h2 id="&#x5BF9;&#x6A21;&#x5757;&#x89E3;&#x6790;&#x903B;&#x8F91;&#x7684;&#x8C03;&#x6574;">&#x5BF9;&#x6A21;&#x5757;&#x89E3;&#x6790;&#x903B;&#x8F91;&#x7684;&#x8C03;&#x6574;</h2>
<p>&#x4ECE; 1.6 &#x5F00;&#x59CB;, TypeScript &#x7F16;&#x8BD1;&#x5668;&#x5BF9;&#x4E8E; &quot;commonjs&quot; &#x7684;&#x6A21;&#x5757;&#x89E3;&#x6790;&#x4F1A;&#x4F7F;&#x7528;&#x4E00;&#x5957;&#x4E0D;&#x540C;&#x7684;&#x89C4;&#x5219;. &#x8FD9;&#x4E9B;<a href="https://github.com/Microsoft/TypeScript/issues/2338" target="_blank">&#x89C4;&#x5219;</a> &#x5C1D;&#x8BD5;&#x6A21;&#x4EFF; Node &#x67E5;&#x627E;&#x6A21;&#x5757;&#x7684;&#x8FC7;&#x7A0B;. &#x8FD9;&#x5C31;&#x610F;&#x5473;&#x7740; node &#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5B83;&#x7684;&#x7C7B;&#x578B;&#x4FE1;&#x606F;, &#x5E76;&#x4E14; TypeScript &#x7F16;&#x8BD1;&#x5668;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;. &#x4E0D;&#x8FC7;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F7F;&#x7528; <code>--moduleResolution</code> &#x547D;&#x4EE4;&#x884C;&#x9009;&#x9879;&#x8986;&#x76D6;&#x6A21;&#x5757;&#x89E3;&#x6790;&#x89C4;&#x5219;. &#x652F;&#x6301;&#x7684;&#x503C;&#x6709;:</p>
<ul>
<li>&apos;classic&apos; - TypeScript 1.6 &#x4EE5;&#x524D;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x4F7F;&#x7528;&#x7684;&#x6A21;&#x5757;&#x89E3;&#x6790;&#x89C4;&#x5219;</li>
<li>&apos;node&apos; - &#x4E0E; node &#x76F8;&#x4F3C;&#x7684;&#x6A21;&#x5757;&#x89E3;&#x6790;</li>
</ul>
<h2 id="&#x5408;&#x5E76;&#x5916;&#x56F4;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x7684;&#x58F0;&#x660E;">&#x5408;&#x5E76;&#x5916;&#x56F4;&#x7C7B;&#x548C;&#x63A5;&#x53E3;&#x7684;&#x58F0;&#x660E;</h2>
<p>&#x5916;&#x56F4;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x63A5;&#x53E3;&#x58F0;&#x660E;&#x6765;&#x6269;&#x5C55;. &#x7C7B;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5BF9;&#x8C61;&#x4E0D;&#x4F1A;&#x88AB;&#x4FEE;&#x6539;. &#x6BD4;&#x5982;&#x8BF4;:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">class</span> Foo {
    <span class="hljs-keyword">public</span> x : <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">interface</span> Foo {
    y : <span class="hljs-built_in">string</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params">foo : Foo</span>)  </span>{
    foo.x = <span class="hljs-number">1</span>; <span class="hljs-comment">// &#x6CA1;&#x95EE;&#x9898;, &#x5728;&#x7C7B; Foo &#x4E2D;&#x6709;&#x58F0;&#x660E;</span>
    foo.y = <span class="hljs-string">&quot;1&quot;</span>; <span class="hljs-comment">// &#x6CA1;&#x95EE;&#x9898;, &#x5728;&#x63A5;&#x53E3; Foo &#x4E2D;&#x6709;&#x58F0;&#x660E;</span>
}
</code></pre>
<h2 id="&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x6536;&#x7A84;&#x51FD;&#x6570;">&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x6536;&#x7A84;&#x51FD;&#x6570;</h2>
<p>TypeScript 1.6 &#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5728; <code>if</code> &#x8BED;&#x53E5;&#x4E2D;&#x6536;&#x7A84;&#x53D8;&#x91CF;&#x7C7B;&#x578B;&#x7684;&#x65B9;&#x5F0F;, &#x4F5C;&#x4E3A;&#x5BF9; <code>typeof</code> &#x548C; <code>instanceof</code> &#x7684;&#x8865;&#x5145;. &#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x6536;&#x7A84;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x6807;&#x6CE8;&#x5F62;&#x5F0F;&#x4E3A; <code>x is T</code>, &#x8FD9;&#x91CC; <code>x</code> &#x662F;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E2D;&#x7684;&#x5F62;&#x53C2;, <code>T</code> &#x662F;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;. &#x5F53;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x7C7B;&#x578B;&#x6536;&#x7A84;&#x51FD;&#x6570;&#x5728; <code>if</code> &#x8BED;&#x53E5;&#x4E2D;&#x88AB;&#x4F20;&#x5165;&#x67D0;&#x4E2A;&#x53D8;&#x91CF;&#x6267;&#x884C;&#x65F6;, &#x8BE5;&#x53D8;&#x91CF;&#x7684;&#x7C7B;&#x578B;&#x4F1A;&#x88AB;&#x6536;&#x7A84;&#x5230; <code>T</code>.</p>
<h3 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h3>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isCat</span>(<span class="hljs-params">a: <span class="hljs-built_in">any</span></span>): <span class="hljs-title">a</span> <span class="hljs-title">is</span> <span class="hljs-title">Cat</span> </span>{
  <span class="hljs-keyword">return</span> a.name === <span class="hljs-string">&apos;kitty&apos;</span>;
}

<span class="hljs-keyword">var</span> x: Cat | Dog;
<span class="hljs-keyword">if</span>(isCat(x)) {
  x.meow(); <span class="hljs-comment">// &#x90A3;&#x4E48;, x &#x5728;&#x8FD9;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x5185;&#x662F; Cat &#x7C7B;&#x578B;</span>
}
</code></pre>
<h2 id="tsconfigjson-&#x5BF9;-exclude-&#x5C5E;&#x6027;&#x7684;&#x652F;&#x6301;"><code>tsconfig.json</code> &#x5BF9; <code>exclude</code> &#x5C5E;&#x6027;&#x7684;&#x652F;&#x6301;</h2>
<p>&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x5199;&#x660E; <code>files</code> &#x5C5E;&#x6027;&#x7684; <code>tsconfig.json</code> &#x6587;&#x4EF6; (&#x9ED8;&#x8BA4;&#x4F1A;&#x5F15;&#x7528;&#x6240;&#x6709;&#x5B50;&#x76EE;&#x5F55;&#x4E0B;&#x7684; *.ts &#x6587;&#x4EF6;) &#x73B0;&#x5728;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4E00;&#x4E2A; <code>exclude</code> &#x5C5E;&#x6027;, &#x6307;&#x5B9A;&#x9700;&#x8981;&#x5728;&#x7F16;&#x8BD1;&#x4E2D;&#x6392;&#x9664;&#x7684;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x76EE;&#x5F55;&#x5217;&#x8868;. <code>exclude</code> &#x5C5E;&#x6027;&#x5FC5;&#x987B;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x7EC4;, &#x5176;&#x4E2D;&#x6BCF;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x6307;&#x5B9A;&#x5BF9;&#x5E94;&#x7684;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x6587;&#x4EF6;&#x5939;&#x540D;&#x79F0;&#x5BF9;&#x4E8E; <code>tsconfig.json</code> &#x6587;&#x4EF6;&#x6240;&#x5728;&#x4F4D;&#x7F6E;&#x7684;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;. &#x4E3E;&#x4F8B;&#x6765;&#x8BF4;:</p>
<pre><code class="lang-json">{
    <span class="hljs-string">&quot;compilerOptions&quot;</span>: {
        <span class="hljs-string">&quot;out&quot;</span>: <span class="hljs-string">&quot;test.js&quot;</span>
    },
    <span class="hljs-string">&quot;exclude&quot;</span>: [
        <span class="hljs-string">&quot;node_modules&quot;</span>,
        <span class="hljs-string">&quot;test.ts&quot;</span>,
        <span class="hljs-string">&quot;utils/t2.ts&quot;</span>
    ]
}
</code></pre>
<p><code>exclude</code> &#x5217;&#x8868;&#x4E0D;&#x652F;&#x6301;&#x901A;&#x914D;&#x7B26;. &#x4EC5;&#x4EC5;&#x53EF;&#x4EE5;&#x662F;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x76EE;&#x5F55;&#x7684;&#x5217;&#x8868;.</p>
<h2 id="-init-&#x547D;&#x4EE4;&#x884C;&#x9009;&#x9879;"><code>--init</code> &#x547D;&#x4EE4;&#x884C;&#x9009;&#x9879;</h2>
<p>&#x5728;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E2D;&#x6267;&#x884C; <code>tsc --init</code> &#x53EF;&#x4EE5;&#x5728;&#x8BE5;&#x76EE;&#x5F55;&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x4E86;&#x9ED8;&#x8BA4;&#x503C;&#x7684; <code>tsconfig.json</code>. &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E00;&#x5E76;&#x4F20;&#x9012;&#x5176;&#x4ED6;&#x9009;&#x9879;&#x6765;&#x751F;&#x6210;&#x521D;&#x59CB;&#x7684; <code>tsconfig.json</code>.</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="TypeScript 1.7.html" class="navigation navigation-prev " aria-label="Previous page: TypeScript 1.7">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="TypeScript 1.5.html" class="navigation navigation-next " aria-label="Next page: TypeScript 1.5">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"TypeScript 1.6","level":"1.7.15","depth":2,"next":{"title":"TypeScript 1.5","level":"1.7.16","depth":2,"path":"doc/release-notes/TypeScript 1.5.md","ref":"./doc/release-notes/TypeScript 1.5.md","articles":[]},"previous":{"title":"TypeScript 1.7","level":"1.7.14","depth":2,"path":"doc/release-notes/TypeScript 1.7.md","ref":"./doc/release-notes/TypeScript 1.7.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/release-notes/TypeScript 1.6.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

